﻿using CloudDiamonds.Models.DBModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Yunzuan.Foundation.DataAccess;

namespace WholesalerService
{
    public class SystemSetting : ISystemSetting
    {
        public SysSettingInfo setting = null;


        ////////////////////////////////裸钻 Loose Diamond      SysSettingID=1////////////////////////////////////////////

        //私有 -裸钻全局 SysSettingID=1  11-10
        public SystemSetting(SystemSettingType type = SystemSettingType.Stock)
        {
            if (setting == null)
            {
                switch (type)
                {
                    case SystemSettingType.Stock:  //库存
                        setting = YZ.Database.QueryForObject<SysSettingInfo>("Syssetting.GetLooseSetting", null);
                        break;
                    case SystemSettingType.Parcel: //统包
                        setting = YZ.Database.QueryForObject<SysSettingInfo>("Syssetting.GetParcelSetting", null);
                        break;
                    case SystemSettingType.Ring:   //成品
                        setting = YZ.Database.QueryForObject<SysSettingInfo>("Syssetting.GetRingSetting", null);
                        break;
                    case SystemSettingType.Gem:    //彩宝
                        setting = YZ.Database.QueryForObject<SysSettingInfo>("Syssetting.GetGemSetting", null);
                        break;
                    case SystemSettingType.Emerald:    //翡翠
                        setting = YZ.Database.QueryForObject<SysSettingInfo>("Syssetting.GetEmeraldSetting", null);
                        break;
                    case SystemSettingType.PrimeGolds:    //翡翠
                        setting = YZ.Database.QueryForObject<SysSettingInfo>("Syssetting.GetPrimeGoldsSetting", null);
                        break;
                    case SystemSettingType.InlaySettings:    //翡翠
                        setting = YZ.Database.QueryForObject<SysSettingInfo>("Syssetting.GetInlaySettings", null);
                        break;
                }

            }
        }

        /// <summary>
        /// 全局销售汇率 -裸钻
        /// </summary>
        /// <returns></returns>
        public decimal GetRate()
        {
            if (setting.Rate.HasValue && setting.Rate > 0)
            {
                return setting.Rate.Value;
            }
            return 1;
        }


        /// <summary>
        /// 全局采购汇率 - 裸钻
        /// </summary>
        /// <returns></returns>
        public decimal GetPurchaseExchangeRate()
        {
            if (setting.PurchaseExchangerate.HasValue && setting.PurchaseExchangerate > 0)
            {
                return setting.PurchaseExchangerate.Value;
            }
            return 1;
        }


        /// <summary>
        /// 全局白钻退点
        /// </summary>
        /// <returns></returns>
        public decimal GetGlobalDiscountReturn()
        {
            if (setting.GlobalDiscountReturn.HasValue)
            {
                return setting.GlobalDiscountReturn.Value;
            }
            return 0;
        }

        /// <summary>
        /// 全局彩钻退点
        /// </summary>
        /// <returns></returns>
        public decimal GetGlobalFancyDiscountReturn()
        {
            if (setting.GlobalFancyDiscountReturn.HasValue)
            {
                return setting.GlobalFancyDiscountReturn.Value;
            }
            return 0;
        }



        public enum SystemSettingType
        {
            /// <summary>
            /// 裸钻
            /// </summary>
            Stock = 1,
            /// <summary>
            /// 统包
            /// </summary>
            Parcel = 2,
            /// <summary>
            /// 成品
            /// </summary>
            Ring = 3,
            /// <summary>
            /// 彩宝
            /// </summary>
            Gem = 4,
            /// <summary>
            /// 翡翠
            /// </summary>
            Emerald=5,
            /// <summary>
            /// 素金
            /// </summary>
            PrimeGolds=6,
            /// <summary>
            /// 空托
            /// </summary>
            InlaySettings = 7

        }
    }
}